package com.etone.smartAudit.controller;

import com.etone.smartAudit.annotation.LoginAdmin;
import com.etone.smartAudit.domain.Admin;
import com.etone.smartAudit.enums.DownloadType;
import com.etone.smartAudit.service.AuditExceptionDownloadService;
import com.etone.smartAudit.vo.PagerVO;
import com.etone.smartAudit.vo.auditException.AuditExceptionDownloadVO;
import com.etone.smartAudit.vo.iapDataMeta.IapDataMetaVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletResponse;
import java.util.*;

/**
 * @author: 张任豪
 * @date: 2022/3/2
 * @description:
 */
@RestController
@AllArgsConstructor
@Api(tags = "项目管理《下载中心》", value = "AuditExceptionDownloadController")
public class AuditExceptionDownloadController {

    private AuditExceptionDownloadService auditExceptionDownloadService;

    @ApiOperation(value = "文件列表 《查询》")
    @GetMapping("/auditExceptionDownload/list")
    public PagerVO<AuditExceptionDownloadVO> list(
            @ApiParam(value = "当前页") @RequestParam(required = false, defaultValue = "1") int page,
            @ApiParam(value = "每页显示数量") @RequestParam(required = false, defaultValue = "10") int pageSize,
            @ApiParam("展示类型(0:导出中,1:导出成功,-1:导出失败,为空:全部记录)") @RequestParam(required = false) Integer state,
            @ApiParam("下载类型(0:地市风险扫描报告,1:地市自动批量报告)") @RequestParam(required = false) Integer type,
            @ApiParam("详情描述") @RequestParam(required = false) String remark,
            @ApiParam("开始分析时间") @RequestParam(required = false) String startTime,
            @ApiParam("结束分析时间") @RequestParam(required = false) String endTime,
            @ApiIgnore @LoginAdmin Admin admin
            ) {
        return auditExceptionDownloadService.voList(page,pageSize,state,type,remark,startTime,endTime,admin);
    }

    @ApiOperation(value = "下载文件《批量》")
    @GetMapping("/auditExceptionDownload/batchDownload/{ids}")
    public void batchDownload(@ApiParam("文件Ids") @PathVariable List<Integer> ids, HttpServletResponse response) {
        auditExceptionDownloadService.batchDownload(ids,response);
    }

    @ApiOperation(value = "下载文件《单个》")
    @GetMapping("/auditExceptionDownload/download/{id}")
    public void download(@ApiParam("文件Id") @PathVariable Integer id, HttpServletResponse response) {
        auditExceptionDownloadService.download(id,response);
    }

    @ApiOperation(value = "删除文件《单个，批量》")
    @DeleteMapping("/auditExceptionDownload/delete/{ids}")
    public void delete(@ApiParam("文件id集合") @PathVariable List<Integer> ids) {
        auditExceptionDownloadService.delete(ids);
    }

    @ApiOperation(value = "获取下载类型")
    @GetMapping("/auditExceptionDownload/getType")
    public List<Map<String,Object>> getType() {
        List<Map<String,Object>> maps = new ArrayList<>();
        for (DownloadType type : DownloadType.values()) {
            Map<String,Object> map = new HashMap<>();
            map.put("name",type.getRemark());
            map.put("type",type.getValue());
            maps.add(map);
        }
        return maps;
    }
}
